package com.hj.dapp.business.customer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hj.dapp.business.customer.model.IntendedCustomer;
import com.hj.dapp.business.customer.service.IntendedCustomerService;
import com.hj.dapp.common.request.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 胡奥程
 * @version 1.0
 * @date 2024/1/22
 */
@RestController
@RequestMapping("/intendedCustomer")
public class IntendedCustomerController {
    @Autowired
    private IntendedCustomerService intendedCustomerService;
    @PutMapping("/save")
    public void save(@RequestBody IntendedCustomer intendedCustomer, Principal principal) {
        intendedCustomerService.save(intendedCustomer,principal);
    }
    @GetMapping("/get/{id}")
    public IntendedCustomer get(@PathVariable("id") Long id) {
        return intendedCustomerService.get(id);
    }
    @PostMapping("/page")
    public IPage<IntendedCustomer> page(@RequestBody PageRequest<IntendedCustomer> request,Principal principal) {
        return intendedCustomerService.page(request,principal);
    }

    @DeleteMapping("/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        intendedCustomerService.delete(id);
    }
    @PostMapping("/edit")
    public void edit(@RequestBody IntendedCustomer intendedCustomer,Principal principal) {
        intendedCustomerService.edit(intendedCustomer,principal);
    }
    @GetMapping("/list/{name}")
    public List<IntendedCustomer> list(@PathVariable("name") String name,Principal principal) {
        return intendedCustomerService.list(name,principal);
    }
    @GetMapping("/listAll")
    public List<IntendedCustomer> listAll(Principal principal) {
        return intendedCustomerService.list(null,principal);
    }
}
